Back to Portfolio
Network Programming

Trivia Server

Multi-Client Network Programming in Python

A TCP socket trivia game where a single server handles multiple clients simultaneously — no threads, just Python's select().

What is this project?

This is a school network programming project — a fully working trivia game over TCP. A Python server accepts connections from multiple clients, authenticates users, serves random questions, tracks scores in real time, and handles clients disconnecting cleanly or abruptly. The core challenge: doing all of this with a single-threaded server using select() for non-blocking I/O multiplexing.

How it works

select() Multiplexing

The server loop calls select() each iteration to find which sockets are ready to read or write — handling N clients without spawning a single thread.

Protocol Layer

chatlib builds and parses fixed-format messages — every packet has a command code, length field, and data payload. Both client and server share the same library.

Score & Auth

Users log in with username + password. Scores update live as players answer questions. A leaderboard command returns all scores sorted in real time.

File Structure

network-campus/
├── server/
│   ├── server_skeleton.py   # main server — select() loop, message handlers
│   └── chatlib.py           # protocol: build_message / parse_message
└── client/
    ├── client.py            # interactive client with menu
    └── chatlib.py           # same protocol library (client side)

How to Run

1

Start the server in one terminal

python server/server_skeleton.py
2

Connect a client in a second terminal

python client/client.py
3

Open more terminals and connect additional clients — the server handles all of them in parallel.

Client Menu

Key Action
1 My Score — see your current score
2 High Score table — see all players ranked
3 Quit — logout and close connection
4 Play — get a trivia question and answer it
5 Logged Users — see who else is connected right now